package com.libs.xxf.simple;

import android.content.Intent;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.SimpleItemAnimator;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.libs.xxf.simple.textactivity.IjkDemo;
import com.libs.xxf.simple.textactivity.TextUpdate;
import com.libs.xxf.simple.textactivity.ZxinDemo;

import java.util.ArrayList;
import java.util.List;


/**
 * TODO: 测试类
 *
 * @author XXF
 *         Create Time : 2017/12/6 16:07
 */
public class MainActivity extends AppCompatActivity {

    private RecyclerView mRecycleView;
    private List<String> list;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        list = new ArrayList<>();
        mRecycleView = findViewById(R.id.recycle);
        mRecycleView.setLayoutManager(new LinearLayoutManager(this));
        ((SimpleItemAnimator) mRecycleView.getItemAnimator()).setSupportsChangeAnimations(false);

        list.add("App更新");
        list.add("IJKplayer");
        list.add("Zxin 二维码扫描");

        SimpleTextAdapter adapter = new SimpleTextAdapter(R.layout.txt_item, list);
        mRecycleView.setAdapter(adapter);
        adapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                String text = ((TextView) view).getText().toString();
                switch (text) {
                    case "App更新":
                        MainActivity.this.startActivity(new Intent(MainActivity.this, TextUpdate
                                .class));
                        break;
                    case "IJKplayer":
                        MainActivity.this.startActivity(new Intent(MainActivity.this, IjkDemo
                                .class));
                        break;
                    case "Zxin 二维码扫描":
                        MainActivity.this.startActivity(new Intent(MainActivity.this,ZxinDemo
                                .class));
                        break;

                    default:
                        break;
                }
            }
        });
    }


    class SimpleTextAdapter extends BaseQuickAdapter<String, BaseViewHolder> {

        SimpleTextAdapter(int layoutResId, @Nullable List<String> data) {
            super(layoutResId, data);
        }

        @Override
        protected void convert(BaseViewHolder helper, String item) {
            helper.setText(R.id.txt_item, item);
        }
    }

}
